﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Maticsoft.Web.OrderInfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int OrderId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(OrderId);
				}
			}
		}
			
	private void ShowInfo(int OrderId)
	{
		Maticsoft.BLL.OrderInfo bll=new Maticsoft.BLL.OrderInfo();
		Maticsoft.Model.OrderInfo model=bll.GetModel(OrderId);
		this.lblOrderId.Text=model.OrderId.ToString();
		this.txtUserId.Text=model.UserId.ToString();
		this.txtReceiveMan.Text=model.ReceiveMan;
		this.txtPayType.Text=model.PayType;
		this.txtOrderTotal.Text=model.OrderTotal.ToString();
		this.txtOrderStatus.Text=model.OrderStatus;
		this.txtOrderTime.Text=model.OrderTime.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtUserId.Text))
			{
				strErr+="UserId格式错误！\\n";	
			}
			if(this.txtReceiveMan.Text.Trim().Length==0)
			{
				strErr+="ReceiveMan不能为空！\\n";	
			}
			if(this.txtPayType.Text.Trim().Length==0)
			{
				strErr+="PayType不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtOrderTotal.Text))
			{
				strErr+="OrderTotal格式错误！\\n";	
			}
			if(this.txtOrderStatus.Text.Trim().Length==0)
			{
				strErr+="OrderStatus不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txtOrderTime.Text))
			{
				strErr+="OrderTime格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int OrderId=int.Parse(this.lblOrderId.Text);
			int UserId=int.Parse(this.txtUserId.Text);
			string ReceiveMan=this.txtReceiveMan.Text;
			string PayType=this.txtPayType.Text;
			decimal OrderTotal=decimal.Parse(this.txtOrderTotal.Text);
			string OrderStatus=this.txtOrderStatus.Text;
			DateTime OrderTime=DateTime.Parse(this.txtOrderTime.Text);


			Maticsoft.Model.OrderInfo model=new Maticsoft.Model.OrderInfo();
			model.OrderId=OrderId;
			model.UserId=UserId;
			model.ReceiveMan=ReceiveMan;
			model.PayType=PayType;
			model.OrderTotal=OrderTotal;
			model.OrderStatus=OrderStatus;
			model.OrderTime=OrderTime;

			Maticsoft.BLL.OrderInfo bll=new Maticsoft.BLL.OrderInfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
